<?php
header('Content-Type:text/html;charset=utf-8');

?>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet"  href="<?php echo backweb_CSS_URL;?>index.css" />
<link rel="stylesheet"  href="<?php echo backweb_CSS_URL;?>common.css" />
<script type="text/javascript" src="<?php echo JS_URL;?>pccs.js"></script>

 <style >
 
.order_details{
	border:2px solid #daf3ff;
}
.order_details:hover{
	border:2px solid #afd9ff;
}
.pcc select{

}

tr.default{
	background: red;
}
.de{
	border:1px solid #ccc;
}
.de tr td{
	padding: 10px;
}



 </style>
 <script type="text/javascript">
 function myBrowser(){
	    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
	    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
	    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
	    var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
	    var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1;
	    if (isIE) {
	        var IE5 = IE55 = IE6 = IE7 = IE8 = false;
	        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
	        reIE.test(userAgent);
	        var fIEVersion = parseFloat(RegExp["$1"]);
	        IE55 = fIEVersion == 5.5;
	        IE6 = fIEVersion == 6.0;
	        IE7 = fIEVersion == 7.0;
	        IE8 = fIEVersion == 8.0;
	        if (IE55) {
	            return "IE55";
	        }
	        if (IE6) {
	            return "IE6";
	        }
	        if (IE7) {
	            return "IE7";
	        }
	        if (IE8) {
	            return "IE8";
	        }
	    }//isIE end
	    if (isFF) {
	        return "FF";
	    }
	    if (isOpera) {
	        return "Opera";
	    }
	    if(isChrome){
			return "Chrome";
	    }
	}

 $(function(){
		$(".addr").click(function (){
			var index = $(this).attr("id");
			$(".main1").hide();
			$(".main2").hide();
			$(".main3").hide();
			$(".main"+index).show();
		});
//		var fm = $("#fm");
		$("#upd").click(function(){
			var r_password = document.getElementById("r_password").value;
			var n_password = document.getElementById("n_password").value;
			var n_confirm_password = document.getElementById("n_confirm_password").value;

			
			if(r_password.length >= 6 && n_password >= 6 && n_confirm_password && n_confirm_password >= 6){
				/*长度判断*/
			/*	if(!myBrowser()){
					var xmlHttpReg = null;
//					xmlHttpReg = new ActiveXObject('Microsoft.XMLHTTP');
					xmlHttpReg = new XMLHttpRequest();
					
//					xmlHttpReg.open('post','./index.php?r=user/updPassword',true);
//					xmlHttpReg.send(null);
//					 xmlHttpReg.onreadystatechange = function (){
//							if(xmlHttpReg.readyState==4){
//								if(xmlHttpReg.status==200){
//									alert(xmlHttpReg.responseText);
//							}}
//					 }
//					xmlHttpReg = new XMLHttpRequest();
					if (xmlHttpReg != null) {

//			               xmlHttpReg.open("post", "./index.php?r=user/updPassword", true);
							xmlHttpReg.open("post", "./index.php?r=user/updPassword", true);
			               xmlHttpReg.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			               xmlHttpReg.send("r_password="+r_password+"&n_password="+n_password+"&n_confirm_password="+n_confirm_password);

							
			               xmlHttpReg.onreadystatechange = function (){
				             if (xmlHttpReg.readyState == 4) {//4代表执行完成

	                            	 if (xmlHttpReg.status == 200) {//200代表执行成功
//	                                document.getElementById("resText").innerHTML = xmlHttpReg.responseText;
	                            		 var a = xmlHttpReg.responseText;
	                            		 alert(a);
										
	                            		/* switch(xmlHttpReg.responseText){
		                 			        
		             						case '0':
		             							alert('密码错误');
		             						break;
		             						case '1':
		             							alert('密码修改成功');
		             							$(".main2").hide();
		             							$(".main1").show();
		             							$("#r_password").val("");
		             							$("#n_password").val("");
		             							$("#n_confirm_password").val("");
		             						break;
		             						case '2':
		             							alert('密码与原来一致');
		             						break;
		             						case '3':
		             							alert('两次密码不一致');
		             						break;
		             						default:
		             							alert('未知错误');
		             						break;
		             					}
	                               }
				                 }
			               }
					}
			    }else{*/

			$.ajaxSetup({ cache: false }); 
			$.ajax({
				url:'./index.php?r=user/updPassword',
				data:{'r_password':r_password,'n_password':n_password,'n_confirm_password':n_confirm_password},
				type:'post',
				dataType:'html',
				cache:false, 
				success:function(data){
					console.log(data);
					switch(data){
						case '0':
							alert('密码错误');
						break;
						case '1':
							alert('密码修改成功');
							$(".main2").hide();
							$(".main1").show();
							$("#r_password").val("");
							$("#n_password").val("");
							$("#n_confirm_password").val("");
						break;
						case '2':
							alert('密码与原来一致');
						break;
						case '3':
							alert('两次密码不一致');
						break;
						default:
							alert('未知错误');
						break;
					}
				},
				error:function(){
					alert('操作失败');
				}
			});
//			}
			}else{
				alert('长度不足6位');
			}
			/*长度判断*/
		});
	 })
 
 </script>
 
	<div id="header">
		<div id="h_info">
			<a href="#" class="title"><img src="<?php echo IMG_URL?>wdxy.png" /></a>
			<ul class="h_nav">
				<li><a href="http://127.0.0.1/xysc/xysc/index.php?r=order/order&user_id=<?php echo Yii::app()->user->id;?>">首页</a></li>
				<li><a href="./index.php?r=user/userinfo&user_id=<?php echo Yii::app()->user->id;?>">账户设置</a></li>
				<li><a href="#">消息</a></li>
			</ul>
			<div class="search"><input type="text" name="search" class="text" /><input type="submit" value="搜索" class="text submit"/></div>
		</div>
	</div>
	<div id="section">
		<div id="sidebar">
			<ul class="detail">
				<li class="change"><a href="javascript:void" disabled="true">物流信息</a>
					<ul>
						<li><a href="#" class="addr" style="color:#000;font-size:12px;"  id="1">我的地址薄</a></li>
					</ul>
				</li>
				<li class="change"><a href="javascript:void" style="font-size:12px;" disabled="true">账户信息</a>
					<ul>
						<li><a href="#" class="addr" style="color:#000;font-size:12px;"  id="2">个人信息管理</a></li>
<!--						<li><a href="#" class="addr" style="color:#000;font-size:12px;"  id="3">密码修改</a></li>-->
					</ul>
				</li>
			</ul>
		</div>
		<div id="main" >
		<div class="main1">
			<?php if(empty($updValues['addr_pro'])){?>
				<?php echo "<form  method='post' action='./index.php?r=user/addr'>";?>
			<?php }else{?>
				<?php echo "<form  method='post' action='./index.php?r=user/addrupd&addr_id=$updValues[addr_id]'>";?>
			<?php }?>
			
				<table class="list_table mt10"  >
				
					<tr>
						 <td class="td_center wh100">原来地区</td>
						 <td>
						        <div class="pcc">
						            <?php echo @$updValues['addr_pro'];?>
						            <?php echo @$updValues['addr_city'];?>
						            <?php echo @$updValues['addr_country'];?>
						        </div>
						        <script language="javascript">
						    </script>
						 </td>		
					 </tr>
				
					<tr>
						 <td class="td_center wh100">所在地区*</td>
						 <td>
						        <div class="pcc">
						            <select name="province" id="province" class="input-text">
						            </select>
						            <select name="city" id="city" class="input-text">
						            </select>
						            <select name="county" id="county" class="input-text"> 
						            </select>
						        </div>
						        <script language="javascript">
						        setup()
						    </script>
						    
						 </td>		
					 </tr>
					  <tr>
						 <td class="td_center wh100">详细地址* </td>
						 <td>
						     <textarea name="addr_details" class="input-text wh500"  cols="25" rows="3" ><?php echo @$updValues['addr_details'];?></textarea>
						 </td>		
					  </tr>	
					  <tr>
						 <td class="td_center wh100">邮政编码 </td>
						 <td>
						    <input type="text" name="addr_zip"  value="<?php echo @$updValues['addr_zip'];?>"  class="input-text" />
						 </td>		
					  </tr>	
					   <tr>
						 <td class="td_center wh100">收货人姓名 </td>
						 <td>
						    <input type="text" name="addr_reciver_name"  value="<?php echo @$updValues['addr_reciver_name'];?>"  class="input-text" />
						 </td>		
					  </tr>	
					  <tr>
						 <td class="td_center wh100">收货人联系方式 </td>
						 <td>
						    <input type="text" name="addr_tel" value="<?php echo @$updValues['addr_tel'];?>"   class="input-text" />
						 </td>		
					  </tr>	
					  <tr>
					<td class="td_center wh100">是否默认：</td>
					<td> <input type="radio" name="addr_default" value="1" <?php if(@$updValues['addr_default'] == 1) echo 'checked="checked"';?>   />是
					         <input type="radio" name="addr_default" value="0" <?php if(@$updValues['addr_default'] == 0) echo 'checked="checked"';?> />否
					</td>
				</tr>
				<tr>
				 <td class="td_center wh100">排序：</td>
				 <td>
					 <input type="text"  name="addr_sort"  value="<?php echo @$updValues['addr_sort'];?>"  class="text sort" style="border:1px solid #ccc;width:40px;"/>
				 </td>		
			  </tr>
				<tr>
					<td class="td_center wh100">是否可用：</td>
					<td> <input type="radio" name="active" value="1"  <?php if(@$updValues['active'] == 1) echo 'checked="checked"';?> />是
					         <input type="radio" name="active" value="0"  <?php if(@$updValues['active'] == 0) echo 'checked="checked"';?> />否
					</td>
				</tr>
				<tr>
				  <td class="td_center">
				    <input type="submit" name="send" id="btsave" value="保存" class="btn btn82 btn_save ml25" />				
				 </td>
				 <td>
				   <input type="reset" value="重置" class="btn btn82 btn_res ml10" />
				</td>
			 </tr>
				</table>
			</form>
			<div class="order">
				<table>
					<tr style="border:1px solid #eee;">
						<th width="10%">省</th>
						<th width="10%">市</th>
						<th width="10%">区</th>
						<th width="10%">详细地址</th>
						<th width="10%">邮编</th>
						<th width="10%">收件人姓名</th>
						<th width="10%">手机</th>
						<th width="5%">是否默认</th>
						<th width="10%">排序</th>
						<th width="10%">操作</th>
						<th width="5%">是否默认</th>
					</tr>
				</table>
				<table class="de">
						
						<?php foreach ($addr_infos as $_v) {?>
						<tr class="<?php if($_v['addr_default'] == 1) echo 'default';?>" style="text-align: center;">
							<td width="10%"><?php echo $_v['addr_pro'];?></td>
							<td width="10%"><?php echo $_v['addr_city'];?></td>
							<td width="10%"><?php echo $_v['addr_country'];?></td>
							<td width="10%"><?php echo $_v['addr_details'];?></td>
							<td width="10%"><?php echo $_v['addr_zip'];?></td>
							<td width="10%"><?php echo $_v['addr_reciver_name'];?></td>
							<td width="10%" ><?php echo $_v['addr_tel'];?></td>
							<td width="5%"><?php echo $active[$_v['addr_default']];?></td>
							<td width="10%"><?php echo $_v['addr_sort'];?></td>
							<td width="10%"><a href="./index.php?r=user/addrupd&addr_id=<?php echo $_v['addr_id'];?>">修改</a> | <a href="#">删除</a></td>
							<td width="5%"><?php echo $active[$_v['active']];?></td>
						</tr>	
						<?php }?>
					
				</table>
			</div>
			</div>
			<div style="display:none" class="main2">
				<form action="./index.php?r=user/updPassword" method="post" id="fm">
				<table class="list_table mt10"  >
					<tr>
					  <td class="td_center">
					    		用户名：
					 </td>
					 <td>
					   <?php echo @$user_info['user_name'];?>
					</td>
				   </tr>
				   
				   <tr>
					  <td class="td_center">
					    		原密码：
					 </td>
					 <td>
					  	<input type="password" name="r_password"  id="r_password"    class="input-text" />
					</td>
				   </tr>
				   
				     <tr>
					  <td class="td_center">
					    		新密码：
					 </td>
					 <td>
					  	<input type="password" name="n_password"  id="n_password"    class="input-text" />
					</td>
				   </tr>
				   
				     <tr>
					  <td class="td_center">
					    		确认密码：
					 </td>
					 <td>
					  	<input type="password" name="n_confirm_password"    class="input-text" id="n_confirm_password"  />
					</td>
				   </tr>
				   
				  
				   <tr>
					  <td class="td_center">
				    	<input type="button" name="send" id="upd" value="保存" class="btn btn82 btn_save ml25" />	
					 </td>
					 <td>
				  		 <input type="reset" value="重置" class="btn btn82 btn_res ml10" />
					</td>
				   </tr>
				</table>
				</form>
		</div>
		</div>	
		
		
	</div>
	
	  